<?php
	/**
	 * Created by PhpStorm.
	 * User: Administrator
	 * Date: 2017/10/10
	 * Time: 16:50
	 */
	namespace app\admin\controller;
	use app\admin\model\Goods_type;
	use think\Controller;
	use think\Db;

	class Product extends Controller
	{
		public function brand(){
			return $this->fetch('product-brand');
		}

		public function category(){
			return $this->fetch('product-category');
		}

		public function plist(){
			return $this->fetch('product-list');
		}

		public function category_add(){
			$m = Db::table('goods_type')->field("*,concat(path,id) as paths")->order('paths desc')->select();
			foreach($m as $k=>$v){
				$m[$k]['name']=str_repeat('|---',$v['level']).$v['name'];
			}
			$this->assign('data',$m);
			return $this->fetch('product-category-add');
		}
		//添加商品分类到数据库
		public function goods_type_add(){
			$data['name']=input('name');
			$data['pid']=input('pid');
			//$self = Db::query("select * from goods_type where id = (select max(id) from goods_type)");
			//$data['path'] = Db::query("select path from goods_type WHERE id={$data['pid']}")[0]['path'].','.($self[0]['id']+1);
			//$data['level']=$self[0]['level']+1;
			//$res = Db::execute("insert goods_type(pid,name,path,level) values()");
			$gt = new Goods_type();
			var_dump($gt->getLastType($data['pid']));
		}
	}